package com.qk.management.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.qk.common.constants.CacheConstants;
import com.qk.domain.business.BusinessCountDO;
import com.qk.domain.clue.ClueCountDO;
import com.qk.management.aop.anno.Cacheable;
import com.qk.management.mapper.BusinessMapper;
import com.qk.management.mapper.ClueMapper;
import com.qk.management.service.ReportOverviewService;
import com.qk.vo.portal.PortalVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * @author: zyx
 * @created: 2025-10-15-14:56
 * @description:
 */
@Slf4j
@Service
public class ReportOverviewServiceImpl implements ReportOverviewService {
    @Autowired
    private ClueMapper clueMapper;
    @Autowired
    private BusinessMapper businessMapper;

    @Override
    public PortalVO overview() {
        ClueCountDO clueCountDO =clueMapper.selectOverview();
        BusinessCountDO businessCountDO =businessMapper.selectOverview();
        PortalVO vo = BeanUtil.copyProperties(clueCountDO, PortalVO.class);
        BeanUtil.copyProperties(businessCountDO, vo);
        return vo;
    }

    @Cacheable(
            keyPrefix = CacheConstants.CACHE_PORTAL_KEY_PREFIX,
            expire = 24*60L,
            timeUnit = TimeUnit.MINUTES
    )
    @Override
    public PortalVO overviewWithCache() {

        ClueCountDO clueCountDO =clueMapper.selectOverview();
        BusinessCountDO businessCountDO =businessMapper.selectOverview();
        PortalVO vo = BeanUtil.copyProperties(clueCountDO, PortalVO.class);
        BeanUtil.copyProperties(businessCountDO, vo);

        return vo;
    }
}
